(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

le(0, y) → true
le(s(x), 0) → false
le(s(x), s(y)) → le(x, y)
minus(x, 0) → x
minus(s(x), s(y)) → minus(x, y)
mod(0, y) → 0
mod(s(x), 0) → 0
mod(s(x), s(y)) → if_mod(le(y, x), s(x), s(y))
if_mod(true, x, y) → mod(minus(x, y), y)
if_mod(false, s(x), s(y)) → s(x)

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^1).


The TRS R consists of the following rules:

le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
minus(x, 0) → x [1]
minus(s(x), s(y)) → minus(x, y) [1]
mod(0, y) → 0 [1]
mod(s(x), 0) → 0 [1]
mod(s(x), s(y)) → if_mod(le(y, x), s(x), s(y)) [1]
if_mod(true, x, y) → mod(minus(x, y), y) [1]
if_mod(false, s(x), s(y)) → s(x) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
minus(x, 0) → x [1]
minus(s(x), s(y)) → minus(x, y) [1]
mod(0, y) → 0 [1]
mod(s(x), 0) → 0 [1]
mod(s(x), s(y)) → if_mod(le(y, x), s(x), s(y)) [1]
if_mod(true, x, y) → mod(minus(x, y), y) [1]
if_mod(false, s(x), s(y)) → s(x) [1]

The TRS has the following type information:
le :: 0:s → 0:s → true:false
0 :: 0:s
true :: true:false
s :: 0:s → 0:s
false :: true:false
minus :: 0:s → 0:s → 0:s
mod :: 0:s → 0:s → 0:s
if_mod :: true:false → 0:s → 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

minus(v0, v1) → null_minus [0]
if_mod(v0, v1, v2) → null_if_mod [0]
le(v0, v1) → null_le [0]
mod(v0, v1) → null_mod [0]

And the following fresh constants:

null_minus, null_if_mod, null_le, null_mod

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

le(0, y) → true [1]
le(s(x), 0) → false [1]
le(s(x), s(y)) → le(x, y) [1]
minus(x, 0) → x [1]
minus(s(x), s(y)) → minus(x, y) [1]
mod(0, y) → 0 [1]
mod(s(x), 0) → 0 [1]
mod(s(x), s(y)) → if_mod(le(y, x), s(x), s(y)) [1]
if_mod(true, x, y) → mod(minus(x, y), y) [1]
if_mod(false, s(x), s(y)) → s(x) [1]
minus(v0, v1) → null_minus [0]
if_mod(v0, v1, v2) → null_if_mod [0]
le(v0, v1) → null_le [0]
mod(v0, v1) → null_mod [0]

The TRS has the following type information:
le :: 0:s:null_minus:null_if_mod:null_mod → 0:s:null_minus:null_if_mod:null_mod → true:false:null_le
0 :: 0:s:null_minus:null_if_mod:null_mod
true :: true:false:null_le
s :: 0:s:null_minus:null_if_mod:null_mod → 0:s:null_minus:null_if_mod:null_mod
false :: true:false:null_le
minus :: 0:s:null_minus:null_if_mod:null_mod → 0:s:null_minus:null_if_mod:null_mod → 0:s:null_minus:null_if_mod:null_mod
mod :: 0:s:null_minus:null_if_mod:null_mod → 0:s:null_minus:null_if_mod:null_mod → 0:s:null_minus:null_if_mod:null_mod
if_mod :: true:false:null_le → 0:s:null_minus:null_if_mod:null_mod → 0:s:null_minus:null_if_mod:null_mod → 0:s:null_minus:null_if_mod:null_mod
null_minus :: 0:s:null_minus:null_if_mod:null_mod
null_if_mod :: 0:s:null_minus:null_if_mod:null_mod
null_le :: true:false:null_le
null_mod :: 0:s:null_minus:null_if_mod:null_mod

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

0 => 0
true => 2
false => 1
null_minus => 0
null_if_mod => 0
null_le => 0
null_mod => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

if_mod(z, z', z'') -{ 1 }→ mod(minus(x, y), y) :|: z = 2, z' = x, z'' = y, x >= 0, y >= 0
if_mod(z, z', z'') -{ 0 }→ 0 :|: v0 >= 0, z'' = v2, v1 >= 0, z = v0, z' = v1, v2 >= 0
if_mod(z, z', z'') -{ 1 }→ 1 + x :|: z' = 1 + x, z = 1, x >= 0, y >= 0, z'' = 1 + y
le(z, z') -{ 1 }→ le(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
le(z, z') -{ 1 }→ 2 :|: y >= 0, z = 0, z' = y
le(z, z') -{ 1 }→ 1 :|: x >= 0, z = 1 + x, z' = 0
le(z, z') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z = v0, z' = v1
minus(z, z') -{ 1 }→ x :|: x >= 0, z = x, z' = 0
minus(z, z') -{ 1 }→ minus(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
minus(z, z') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z = v0, z' = v1
mod(z, z') -{ 1 }→ if_mod(le(y, x), 1 + x, 1 + y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
mod(z, z') -{ 1 }→ 0 :|: y >= 0, z = 0, z' = y
mod(z, z') -{ 1 }→ 0 :|: x >= 0, z = 1 + x, z' = 0
mod(z, z') -{ 0 }→ 0 :|: v0 >= 0, v1 >= 0, z = v0, z' = v1

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V13),0,[le(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V13),0,[minus(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V13),0,[mod(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V13),0,[fun(V, V1, V13, Out)],[V >= 0,V1 >= 0,V13 >= 0]).
eq(le(V, V1, Out),1,[],[Out = 2,V2 >= 0,V = 0,V1 = V2]).
eq(le(V, V1, Out),1,[],[Out = 1,V3 >= 0,V = 1 + V3,V1 = 0]).
eq(le(V, V1, Out),1,[le(V4, V5, Ret)],[Out = Ret,V1 = 1 + V5,V4 >= 0,V5 >= 0,V = 1 + V4]).
eq(minus(V, V1, Out),1,[],[Out = V6,V6 >= 0,V = V6,V1 = 0]).
eq(minus(V, V1, Out),1,[minus(V7, V8, Ret1)],[Out = Ret1,V1 = 1 + V8,V7 >= 0,V8 >= 0,V = 1 + V7]).
eq(mod(V, V1, Out),1,[],[Out = 0,V9 >= 0,V = 0,V1 = V9]).
eq(mod(V, V1, Out),1,[],[Out = 0,V10 >= 0,V = 1 + V10,V1 = 0]).
eq(mod(V, V1, Out),1,[le(V11, V12, Ret0),fun(Ret0, 1 + V12, 1 + V11, Ret2)],[Out = Ret2,V1 = 1 + V11,V12 >= 0,V11 >= 0,V = 1 + V12]).
eq(fun(V, V1, V13, Out),1,[minus(V14, V15, Ret01),mod(Ret01, V15, Ret3)],[Out = Ret3,V = 2,V1 = V14,V13 = V15,V14 >= 0,V15 >= 0]).
eq(fun(V, V1, V13, Out),1,[],[Out = 1 + V16,V1 = 1 + V16,V = 1,V16 >= 0,V17 >= 0,V13 = 1 + V17]).
eq(minus(V, V1, Out),0,[],[Out = 0,V18 >= 0,V19 >= 0,V = V18,V1 = V19]).
eq(fun(V, V1, V13, Out),0,[],[Out = 0,V20 >= 0,V13 = V21,V22 >= 0,V = V20,V1 = V22,V21 >= 0]).
eq(le(V, V1, Out),0,[],[Out = 0,V23 >= 0,V24 >= 0,V = V23,V1 = V24]).
eq(mod(V, V1, Out),0,[],[Out = 0,V25 >= 0,V26 >= 0,V = V25,V1 = V26]).
input_output_vars(le(V,V1,Out),[V,V1],[Out]).
input_output_vars(minus(V,V1,Out),[V,V1],[Out]).
input_output_vars(mod(V,V1,Out),[V,V1],[Out]).
input_output_vars(fun(V,V1,V13,Out),[V,V1,V13],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [minus/3]
1. recursive : [le/3]
2. recursive : [fun/4, (mod)/3]
3. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into minus/3
1. SCC is partially evaluated into le/3
2. SCC is partially evaluated into (mod)/3
3. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations minus/3
* CE 10 is refined into CE [21]
* CE 8 is refined into CE [22]
* CE 9 is refined into CE [23]


### Cost equations --> "Loop" of minus/3
* CEs [23] --> Loop 14
* CEs [21] --> Loop 15
* CEs [22] --> Loop 16

### Ranking functions of CR minus(V,V1,Out)
* RF of phase [14]: [V,V1]

#### Partial ranking functions of CR minus(V,V1,Out)
* Partial RF of phase [14]:
- RF of loop [14:1]:
V
V1


### Specialization of cost equations le/3
* CE 20 is refined into CE [24]
* CE 18 is refined into CE [25]
* CE 17 is refined into CE [26]
* CE 19 is refined into CE [27]


### Cost equations --> "Loop" of le/3
* CEs [27] --> Loop 17
* CEs [24] --> Loop 18
* CEs [25] --> Loop 19
* CEs [26] --> Loop 20

### Ranking functions of CR le(V,V1,Out)
* RF of phase [17]: [V,V1]

#### Partial ranking functions of CR le(V,V1,Out)
* Partial RF of phase [17]:
- RF of loop [17:1]:
V
V1


### Specialization of cost equations (mod)/3
* CE 12 is refined into CE [28,29]
* CE 15 is refined into CE [30]
* CE 11 is refined into CE [31,32,33,34,35]
* CE 14 is refined into CE [36]
* CE 16 is refined into CE [37]
* CE 13 is refined into CE [38,39,40,41]


### Cost equations --> "Loop" of (mod)/3
* CEs [41] --> Loop 21
* CEs [40] --> Loop 22
* CEs [39] --> Loop 23
* CEs [38] --> Loop 24
* CEs [29] --> Loop 25
* CEs [31] --> Loop 26
* CEs [30] --> Loop 27
* CEs [28] --> Loop 28
* CEs [32] --> Loop 29
* CEs [33,34,35,36,37] --> Loop 30

### Ranking functions of CR mod(V,V1,Out)
* RF of phase [21]: [V-1,V-V1+1]
* RF of phase [23]: [V]

#### Partial ranking functions of CR mod(V,V1,Out)
* Partial RF of phase [21]:
- RF of loop [21:1]:
V-1
V-V1+1
* Partial RF of phase [23]:
- RF of loop [23:1]:
V


### Specialization of cost equations start/3
* CE 4 is refined into CE [42,43,44,45,46,47,48,49,50]
* CE 2 is refined into CE [51]
* CE 3 is refined into CE [52]
* CE 5 is refined into CE [53,54,55,56,57]
* CE 6 is refined into CE [58,59,60]
* CE 7 is refined into CE [61,62,63,64,65,66,67]


### Cost equations --> "Loop" of start/3
* CEs [64] --> Loop 31
* CEs [54,58,63] --> Loop 32
* CEs [46] --> Loop 33
* CEs [47] --> Loop 34
* CEs [42,43,44,45,48,49,50] --> Loop 35
* CEs [62] --> Loop 36
* CEs [52] --> Loop 37
* CEs [51,53,55,56,57,59,60,61,65,66,67] --> Loop 38

### Ranking functions of CR start(V,V1,V13)

#### Partial ranking functions of CR start(V,V1,V13)


Computing Bounds
=====================================

#### Cost of chains of minus(V,V1,Out):
* Chain [[14],16]: 1*it(14)+1
Such that:it(14) =< V1

with precondition: [V=Out+V1,V1>=1,V>=V1]

* Chain [[14],15]: 1*it(14)+0
Such that:it(14) =< V1

with precondition: [Out=0,V>=1,V1>=1]

* Chain [16]: 1
with precondition: [V1=0,V=Out,V>=0]

* Chain [15]: 0
with precondition: [Out=0,V>=0,V1>=0]


#### Cost of chains of le(V,V1,Out):
* Chain [[17],20]: 1*it(17)+1
Such that:it(17) =< V

with precondition: [Out=2,V>=1,V1>=V]

* Chain [[17],19]: 1*it(17)+1
Such that:it(17) =< V1

with precondition: [Out=1,V1>=1,V>=V1+1]

* Chain [[17],18]: 1*it(17)+0
Such that:it(17) =< V1

with precondition: [Out=0,V>=1,V1>=1]

* Chain [20]: 1
with precondition: [V=0,Out=2,V1>=0]

* Chain [19]: 1
with precondition: [V1=0,Out=1,V>=1]

* Chain [18]: 0
with precondition: [Out=0,V>=0,V1>=0]


#### Cost of chains of mod(V,V1,Out):
* Chain [[23],30]: 7*it(23)+1*s(5)+2
Such that:s(5) =< 1
aux(5) =< V
it(23) =< aux(5)

with precondition: [V1=1,Out=0,V>=1]

* Chain [[23],26]: 5*it(23)+2
Such that:aux(6) =< V
it(23) =< aux(6)

with precondition: [V1=1,Out=0,V>=2]

* Chain [[23],24,30]: 5*it(23)+2*s(5)+5
Such that:aux(7) =< 1
aux(8) =< V
s(5) =< aux(7)
it(23) =< aux(8)

with precondition: [V1=1,Out=0,V>=2]

* Chain [[21],30]: 8*it(21)+1*s(5)+2
Such that:s(5) =< V1
aux(12) =< V
it(21) =< aux(12)

with precondition: [Out=0,V1>=2,V>=V1]

* Chain [[21],29]: 4*it(21)+2*s(14)+2
Such that:it(21) =< V-V1+1
aux(13) =< V
it(21) =< aux(13)
s(14) =< aux(13)

with precondition: [Out=0,V1>=2,V>=V1+1]

* Chain [[21],28]: 4*it(21)+2*s(14)+3
Such that:it(21) =< V-V1+1
aux(14) =< V
it(21) =< aux(14)
s(14) =< aux(14)

with precondition: [Out=1,V1>=2,V>=V1+1]

* Chain [[21],25]: 4*it(21)+2*s(14)+1*s(16)+3
Such that:aux(10) =< V
it(21) =< V-V1+1
aux(11) =< V-Out
s(16) =< Out
it(21) =< aux(10)
s(15) =< aux(10)
it(21) =< aux(11)
s(15) =< aux(11)
s(14) =< s(15)

with precondition: [Out>=2,V1>=Out+1,V>=Out+V1]

* Chain [[21],22,30]: 4*it(21)+3*s(5)+2*s(14)+5
Such that:aux(10) =< V
aux(16) =< V1
aux(17) =< V-V1
it(21) =< aux(17)
s(5) =< aux(16)
it(21) =< aux(10)
s(15) =< aux(10)
s(15) =< aux(17)
s(14) =< s(15)

with precondition: [Out=0,V1>=2,V>=2*V1]

* Chain [30]: 2*s(3)+1*s(5)+2
Such that:s(5) =< V1
aux(1) =< V
s(3) =< aux(1)

with precondition: [Out=0,V>=0,V1>=0]

* Chain [29]: 2
with precondition: [V=1,Out=0,V1>=2]

* Chain [28]: 3
with precondition: [V=1,Out=1,V1>=2]

* Chain [27]: 1
with precondition: [V1=0,Out=0,V>=1]

* Chain [26]: 2
with precondition: [V1=1,Out=0,V>=1]

* Chain [25]: 1*s(16)+3
Such that:s(16) =< V

with precondition: [V=Out,V>=2,V1>=V+1]

* Chain [24,30]: 2*s(5)+5
Such that:aux(7) =< 1
s(5) =< aux(7)

with precondition: [V1=1,Out=0,V>=1]

* Chain [22,30]: 3*s(5)+5
Such that:aux(16) =< V1
s(5) =< aux(16)

with precondition: [Out=0,V1>=2,V>=V1]


#### Cost of chains of start(V,V1,V13):
* Chain [38]: 12*s(48)+19*s(50)+12*s(54)+4*s(58)+2*s(60)+5
Such that:s(53) =< V-V1
aux(23) =< V
aux(24) =< V-V1+1
aux(25) =< V1
s(50) =< aux(23)
s(54) =< aux(24)
s(48) =< aux(25)
s(58) =< s(53)
s(58) =< aux(23)
s(59) =< aux(23)
s(59) =< s(53)
s(60) =< s(59)
s(54) =< aux(23)

with precondition: [V>=0,V1>=0]

* Chain [37]: 1
with precondition: [V=1,V1>=1,V13>=1]

* Chain [36]: 3
with precondition: [V=1,V1>=2]

* Chain [35]: 4*s(73)+18*s(77)+21*s(81)+12*s(93)+4*s(97)+2*s(99)+18*s(100)+7
Such that:aux(26) =< V1
s(73) =< V1+1
s(92) =< V1-2*V13
aux(30) =< V1-2*V13+1
aux(31) =< V1-V13
aux(32) =< V13
s(93) =< aux(30)
s(100) =< aux(31)
s(81) =< aux(32)
s(77) =< aux(26)
s(73) =< aux(26)
s(97) =< s(92)
s(97) =< aux(31)
s(98) =< aux(31)
s(98) =< s(92)
s(99) =< s(98)
s(93) =< aux(31)

with precondition: [V=2,V1>=0,V13>=0]

* Chain [34]: 6*s(114)+17*s(118)+7
Such that:s(116) =< V1
aux(33) =< 1
s(114) =< aux(33)
s(118) =< s(116)

with precondition: [V=2,V13=1,V1>=2]

* Chain [33]: 1*s(119)+5
Such that:s(119) =< V13

with precondition: [V=2,V1=V13+1,V1>=3]

* Chain [32]: 1
with precondition: [V1=0,V>=0]

* Chain [31]: 5*s(122)+17*s(123)+5
Such that:s(120) =< 1
s(121) =< V
s(122) =< s(120)
s(123) =< s(121)

with precondition: [V1=1,V>=1]


Closed-form bounds of start(V,V1,V13):
-------------------------------------
* Chain [38] with precondition: [V>=0,V1>=0]
- Upper bound: 21*V+12*V1+5+nat(V-V1+1)*12+nat(V-V1)*4
- Complexity: n
* Chain [37] with precondition: [V=1,V1>=1,V13>=1]
- Upper bound: 1
- Complexity: constant
* Chain [36] with precondition: [V=1,V1>=2]
- Upper bound: 3
- Complexity: constant
* Chain [35] with precondition: [V=2,V1>=0,V13>=0]
- Upper bound: 22*V1+21*V13+11+nat(V1-2*V13+1)*12+nat(V1-V13)*20+nat(V1-2*V13)*4
- Complexity: n
* Chain [34] with precondition: [V=2,V13=1,V1>=2]
- Upper bound: 17*V1+13
- Complexity: n
* Chain [33] with precondition: [V=2,V1=V13+1,V1>=3]
- Upper bound: V13+5
- Complexity: n
* Chain [32] with precondition: [V1=0,V>=0]
- Upper bound: 1
- Complexity: constant
* Chain [31] with precondition: [V1=1,V>=1]
- Upper bound: 17*V+10
- Complexity: n

### Maximum cost of start(V,V1,V13): max([max([17*V+9,nat(V13)+4]),12*V1+4+max([5*V1+2+max([6,nat(V13)*21+V1+ (4*V1+4)+nat(V1-2*V13+1)*12+nat(V1-V13)*20+nat(V1-2*V13)*4]),nat(V-V1+1)*12+21*V+nat(V-V1)*4])])+1
Asymptotic class: n
* Total analysis performed in 463 ms.

(10) BOUNDS(1, n^1)